﻿using System;
using System.Linq;
using Project.MVC.PhanQuyen.IDAL;
using Project.MVC.PhanQuyen.Model;
using Project.MVC.PhanQuyen.MsSQLDAL;

namespace Project.MVC.PhanQuyen.Services
{
    public class PQNhatKyServices : IPQNhatKyServices
    {
        IPQNhatKy repository = null;
        
		public PQNhatKyServices()
            : this( new PQNhatKyRepository() )
		{                        
		}

        public PQNhatKyServices(IPQNhatKy rep)
        {
            repository = rep;
            if(repository == null)
                throw new InvalidOperationException("Repository cann't be null");
        }

        #region IPQNhatKyServices Members

        public IQueryable<PQNhatKyInfo> GetList2Grid(DateTime? tuNgay, DateTime? denNgay)
        {
            try
            {
                return repository.GetList().Where(record =>
                                                (tuNgay == null || record.ThoiGian >= tuNgay) &&
                                                (denNgay == null || record.ThoiGian <= denNgay));
                                            
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void Insert(PQNhatKyInfo value)
        {
            try
            {
                repository.Insert(value);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void Delete(PQNhatKyInfo value)
        {
            try
            {
                repository.Delete(value);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void Delete()
        {
            try
            {
                repository.Delete();
            }
            catch (Exception)
            {
                throw;
            }
        }

        #endregion

        #region IPQNhatKyServices Members


        public void Delete(int[] ids)
        {
            try
            {
                repository.Delete(ids);
            }
            catch (Exception)
            {
                throw;
            }
        }

        #endregion
    }
}